/**********************************************************
 *
 * @author Rossi java@rosstauscher.de
 *********************************************************/

package de.rosstauscher.jculfw.homematic;

import java.util.regex.Pattern;

import de.rosstauscher.jculfw.homematic.events.HomeMaticRemoteButtonEvent;

/**********************************************************
 * Some constants and util methods.
 * @author Rossi java@rosstauscher.de
 *********************************************************/

public class HomeMaticUtil {
	
	public static String BROAD_CAST_ADDRESS = "000000";

	public static final String CMD_NACK = "8002"; // ACK / NACK command
	
	// Diverse pairing request commands.
	public static final String[] LCMD_PAIR_REQUEST = {"1A8400", "1A8000", "1A0400"};
	
	/**********************************************************
	 * Parse the given data and package it into a "Remote device" event if applicable.
	 * @param length
	 * @param count
	 * @param control
	 * @param msgType
	 * @param sender
	 * @param destination
	 * @param payLoad
	 * @return a HomeMaticRemoteButtonEvent or null if the data does not come from a "Remote" 
	 *********************************************************/
	
	public static HomeMaticRemoteButtonEvent parseRemoteCommand(String length, String count, String control, String msgType, String sender, String destination, String payLoad) {
		String command = control+msgType;
		if (Pattern.matches("..4.", command) && payLoad.length() > 3) {
			return new HomeMaticRemoteButtonEvent(length, count, control, msgType, sender, destination, payLoad);
		}
		return null;
	}
	
}
